package com.cuitrip.business.bill;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.cuitrip.app.UserConfig;
import com.cuitrip.component.choicedialog.ChoiceDialog;
import com.cuitrip.service.R;
import com.lab.app.customui.CustomUiConfig;
import com.lab.app.customui.CustomUiFragmentActivity;
import com.lab.utils.Utils;

/**
 * Created by MiJack on 2015/10/20.
 */
public class BindPayPalActivity extends CustomUiFragmentActivity {
    public static final String KEY_RESULT = "KEY_RESULT";
    private EditText editMInput1;
    private TextView submit;

    @Override
    public boolean initCloseTopBar() {
        return false;
    }

    @Override
    public CustomUiConfig initCustomUiConfig() {
        CustomUiConfig config=new CustomUiConfig();
        config.mTopbarMiddleAreaName=getString(R.string.account_paypal);
        config.mTopbarLeftAreaName=getString(R.string.back_icon);
        return config;
    }

    @Override
    public void onTopbarLeftPress() {
        finish();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState, R.layout.activity_bind_paypal);
        editMInput1 = (EditText) findViewById(R.id.editMInput1);
        submit = (TextView) findViewById(R.id.submit);
        submit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                final String result = editMInput1.getText().toString();
                if (TextUtils.isEmpty(result)) {
                    Utils.shakeView(findViewById(R.id.ll));
                    return;
                }
                ChoiceDialog choiceDialog = ChoiceDialog.getInstance();
                choiceDialog.setDialogTitle(getResources().getString(R.string.account_paypal));
                choiceDialog.setDialogTitleDividerVisibility(false);
                choiceDialog.setDialogMessage(getResources().getString(R.string.account_paypal_set_confirm, result));
                choiceDialog.setDialogCoupleStyleSetting(
                        getResources().getString(R.string.operation_yes),
                        getResources().getString(R.string.operation_cancel), new ChoiceDialog.DialogStyleCoupleCallback() {
                            @Override
                            public boolean onPositiveButtonClick() {
                                finish(result);
                                return false;
                            }

                            @Override
                            public boolean onNegativeButtonClick() {
                                return false;
                            }
                        });
                showDialogFragment(choiceDialog);
            }
        });
    }

    private void finish(String result) {
        setResult(RESULT_OK, new Intent().putExtra(KEY_RESULT, result));
        UserConfig.setPaypalAccount(result);
        finish();
    }


    private static final String KEY_VALUE = "KEY_VALUE";

    public static void startBindActivityForResult(Activity activity, String value, int requestCode) {
        Bundle bundle = new Bundle();
        bundle.putString(KEY_VALUE, value);
        Intent intent = new Intent(activity, BindPayPalActivity.class);
        intent.putExtras(bundle);
        activity.startActivityForResult(intent, requestCode);
    }
}
